package org.shiwen.week11.answer;

import java.util.InputMismatchException;
import java.util.Scanner;

public class StudentManagementSystem {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        Student s = new Student();
        System.out.println("请输入姓名：");
        while (true) {
            try{
                String name = sc.next();
                if(Student.isValidName(name)){
                    s.setName(name);
                    break;
                }else{
                    NameInputException e =  new NameInputException(name);
                    throw e;
                }
            } catch (NameInputException e) {
                System.out.println(e.getMessage());
                System.out.println("请输入姓名：");
            }
        }
        System.out.println("请输入年龄：");
        while (true) {
            try{
                int age = sc.nextInt();
                if(Student.isValidAge(age)){
                    s.setAge(age);
                    break;
                }else{
                    AgeInputException e =  new AgeInputException(String.valueOf(age));
                    throw e;
                }
            } catch (InputMismatchException e){
                System.out.println("请输入数字，而非字符串");
                System.out.println("请输入年龄：");
                sc.nextLine();
            } catch (AgeInputException e) {
                System.out.println(e.getMessage());
                System.out.println("请输入年龄：");
            }
        }
        System.out.println(s.showInfo());

    }
}
